package com.it;

public class Test5 {
    public static void main(String[] args) {
    //把一个数组中的元素复制到另一个新数组中去
        int[] arr={1,2,3,4,5};
        int[] arr2=copyArr(arr);
        printArr(arr2);
    }
    public static void printArr(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i==arr.length-1) {
                System.out.print(arr[i]);
            }else{
                System.out.print(arr[i]+",");
            }
        }
        System.out.print("]");
    }
    public static int[] copyArr(int[] arr) {
        int[] arr2=new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            arr2[i]=arr[i];
        }
        return arr2;
    }
}
